#pragma once

//
class CTestOcfCliDlg;
class COcfClient;

//
#define MAX_PACKET_SIZE			100000
typedef __OCF_BASE__::CBaseThread<__OCF_BASE__::CMemPoolDefaultAllocator> _OCFTHREAD_T;
typedef __OCF_BASE__::CTcpCommCli<__OCF_BASE__::CMemPoolDefaultAllocator> _OCFCLI_T;

typedef __OCF_PROXY__::CUserToLogin<COcfClient> _USER_TO_LOGIN_T;
typedef __OCF_STUB__::CLoginToUser<COcfClient> _LOGIN_TO_USER_T;

typedef __OCF_PROXY__::CUserToGateway<COcfClient> _USER_TO_GATEWAY_T;
typedef __OCF_STUB__::CGatewayToUser<COcfClient> _GATEWAY_TO_USER_T;

//
#define __USE_THREAD_FOR_CLI__

#ifdef __USE_THREAD_FOR_CLI__
class COcfClient: protected _OCFTHREAD_T,  public _OCFCLI_T, public _USER_TO_LOGIN_T, public _LOGIN_TO_USER_T
														   , public _USER_TO_GATEWAY_T, public _GATEWAY_TO_USER_T
{
#else
class COcfClient: public _OCFCLI_T, public _USER_TO_LOGIN_T, public _LOGIN_TO_USER_T
								  , public _USER_TO_GATEWAY_T, public _GATEWAY_TO_USER_T
{
#endif
public:
	COcfClient(CTestOcfCliDlg* pcMain);
	virtual ~COcfClient();

	BOOL InitCli();
	void UninitCli();
	long Send(const ULONG ulCnt, const ULONG aulBindx[], const ULONG aulIdentity[], const BYTE byST, const ULONG ulLen, const BYTE* pbyData);

public:
#ifdef __USE_THREAD_FOR_CLI__
	virtual BOOL _OCFTHREAD_T::Do();
#else
	virtual BOOL Do();
#endif
	virtual void Pop(LONG lLen, const unsigned char* pchData, LONG& lUsedLen);
	virtual void HandleSessionTimeout();
	virtual void HandleError(TCPCOMMCLI_ERROR_CATEGORY enumErrorCategory, LONG ErrorCode, LONG lLen = 0, const BYTE* pchData = NULL);
	virtual void HandleConnect();
	virtual void HandleClose();
	virtual void OnPacket(BYTE byST, ULONG ulLen, const BYTE* pbyData);

public:
	long fnResultCheckAuth(ULONG ulBindX, ULONG ulIdentity, int nLenUserID, char* pszUserID, BYTE byRes); 
	long fnResultCharLoading(ULONG ulBindX, ULONG ulIdentity, BYTE byRes, int nLenCharData, char* pCharData);
	long fnResultCharCreate(ULONG ulBindX, ULONG ulIdentity, BYTE byRes);
	long fnResultCharDelete(ULONG ulBindX, ULONG ulIdentity, BYTE byRes);
	long fnResultCharSelect(ULONG ulBindX, ULONG ulIdentity, BYTE byRes);


private:
	BYTE m_achTmp[MAX_PACKET_SIZE];
	CTestOcfCliDlg* m_pcMain;
};

